package com.woniuxy.woniuhis.service.impl;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.woniuxy.woniuhis.entity.MedicineCost;
import com.woniuxy.woniuhis.exception.MedicineCostServiceException;
import com.woniuxy.woniuhis.mapper.MedicineCostMapper;
import com.woniuxy.woniuhis.service.MedicineCostService;

@Service
public class MedicineCostServiceImpl implements MedicineCostService{

	@Autowired
	MedicineCostMapper medicineCostMapper;
	

	/* 
	 * 根据进料id找进料
	 */
	@Override
	public List<MedicineCost> findMedicineCostById(MedicineCost medicineCost) {
		try {
			
			List<MedicineCost> mediCosts = medicineCostMapper.selectMediByMediId(medicineCost);
			return mediCosts;
			
		} catch (Exception e) {
			
			System.out.println("findMedicineCostById错误");
			e.printStackTrace();
			throw new MedicineCostServiceException("findMedicineCostById错误");
			
		}
	}

	/* 
	 * 根据进料名字找进料
	 */
	@Override
	public List<MedicineCost> findMedicineCostByName(MedicineCost medicineCost) {
		
		try {
			
			List<MedicineCost> mediCosts = medicineCostMapper.selectMediByMediName(medicineCost);
			return mediCosts;
			
		} catch (Exception e) {
			
			System.out.println("findMedicineCostByName错误");
			e.printStackTrace();
			throw new MedicineCostServiceException("findMedicineCostByName错误");
			
		}
	}


	/* 
	 * 添加一个药物
	 */
	@Override
	public void addMedicineCost(MedicineCost medicineCost) {
		try {
			
			System.out.println("添加");
			medicineCost.setMediId(UUID.randomUUID().toString());
			medicineCostMapper.insertMedi(medicineCost);
			
		} catch (Exception e) {
			
			System.out.println("addMedicine错误");
			e.printStackTrace();
			throw new MedicineCostServiceException("addMedicine错误");
			
		}
		
	}


	/* 
	 * 修改药物的服务方法
	 */
	@Override
	public void modifyMedicineCost(MedicineCost medicineCost) {
		try {
			
			System.out.println("修改");
			medicineCostMapper.updateMedi(medicineCost);
			
		} catch (Exception e) {
			
			System.out.println("modifyMedicineCost错误");
			e.printStackTrace();
			throw new MedicineCostServiceException("modifyMedicineCost错误");
			
		}
		
	}


	@Override
	public void delMedicineCostByMediID(MedicineCost medicineCost) {
		try {
			
			System.out.println("删除:"+medicineCost.getMediId());
			
			medicineCostMapper.deleteMedi(medicineCost);
			
		} catch (Exception e) {
			
			System.out.println("delMedicineByMediID错误");
			e.printStackTrace();
			throw new MedicineCostServiceException("delMedicineByMediID错误");
			
		}
	}



	@Override
	public List<MedicineCost> findAllMedicineCost() {
		// TODO Auto-generated method stub
		return null;
	}



}
